<template>
  <div>
    <h1>我是didi</h1>
    <h1>{{count}}</h1>
    <button @click="byebye">拜拜</button>
  </div>
</template>

<script>
import PubSub from "pubsub-js";
export default {
    name : "Didi",
    data () {
        return {
            count: 0,
            pubId:null,
        }
    },
    mounted(){
         this.pubId = PubSub.subscribe("count", (_, count) => {
      console.log(count);
      this.count = count;
    });
    },
   methods: {
       byebye() {
      //unsubscribe也可接受一个订阅id(pubId),是订阅方法的返回值,可以取消当前组件的当前订阅
       PubSub.unsubscribe(this.pubId);
    },
  },
}
</script>

<style>

</style>